package com.tbq.tbqj_ggl.activity

import android.os.Bundle
import android.view.KeyEvent
import android.view.View
import android.widget.Button
import com.tbq.sdk.TBQ
import com.tbq.tbqj_ggl.R
import com.tbq.tbqj_ggl.app.BaseActivity
import com.tbq.tbqj_ggl.utils.AudioHandleUtils
import com.tbq.tbqj_ggl.windows.ScratchPrizeTypeWindow
import com.tbq.tbqj_ggl.windows.TowerGameExitWindows


class ScratchGameTypeActivity : BaseActivity(), View.OnClickListener, ScratchPrizeTypeWindow.Listener {
    private var btbaifenbai: Button? = null
    private var bthaoyun: Button? = null
    private var btyigua: Button? = null
    private var btzhaocai: Button? = null
    private var btdaji: Button? = null
    private var btwubei: Button? = null
    private var btjingqing: Button? = null
    private val scratchPrizeTypeWindow by lazy { ScratchPrizeTypeWindow(this, this) }
    private var type: Int = 0

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        TBQ.initTBQ(this)
    }

    private fun addView() {
        btbaifenbai = findViewById(R.id.scratch_prizes_game_type_bt_baifenbai) as Button
        bthaoyun = findViewById(R.id.scratch_prizes_game_type_bt_haoyun) as Button
        btyigua = findViewById(R.id.scratch_prizes_game_type_bt_yigua) as Button
        btzhaocai = findViewById(R.id.scratch_prizes_game_type_bt_zhaocai) as Button
        btdaji = findViewById(R.id.scratch_prizes_game_type_bt_fklc) as Button
        btwubei = findViewById(R.id.scratch_prizes_game_type_bt_wubei) as Button
        btjingqing = findViewById(R.id.scratch_prizes_game_type_bt_jingqing) as Button
        btbaifenbai!!.setOnClickListener(this)
        bthaoyun!!.setOnClickListener(this)
        btyigua!!.setOnClickListener(this)
        btzhaocai!!.setOnClickListener(this)
        btdaji!!.setOnClickListener(this)
        btwubei!!.setOnClickListener(this)
        btjingqing!!.setOnClickListener(this)
    }

    override fun onDrawFinish() {
        super.onDrawFinish()
        when (TBQ.get("PLAY_GAME_GGL_TYPE")) {
            "1" -> scratchPrizeTypeWindow.startupWindows(1)
            "2" -> scratchPrizeTypeWindow.startupWindows(2)
            "3" -> scratchPrizeTypeWindow.startupWindows(3)
            "4" -> scratchPrizeTypeWindow.startupWindows(4)
            "5" -> scratchPrizeTypeWindow.startupWindows(5)
            else ->{
                if (TBQ.get("KEY_IS_MOBILE") == "1") {
                    setContentView(R.layout.mobile_scratch_prizes_game_type)
                } else {
                    setContentView(R.layout.activity_scratch_prizes_game_type)
                }
                addView()
            }
        }

        AudioHandleUtils.getInstance().initConfig(applicationContext)
    }

    override fun clickListener(number: Int) {
        type = number
    }

    override fun onClick(v: View) {
        when (v.id) {
            R.id.scratch_prizes_game_type_bt_baifenbai -> scratchPrizeTypeWindow.showCenter(1)
            R.id.scratch_prizes_game_type_bt_haoyun -> scratchPrizeTypeWindow.showCenter(2)
            R.id.scratch_prizes_game_type_bt_yigua -> scratchPrizeTypeWindow.showCenter(3)
            R.id.scratch_prizes_game_type_bt_zhaocai -> scratchPrizeTypeWindow.showCenter(4)
            R.id.scratch_prizes_game_type_bt_fklc -> scratchPrizeTypeWindow.showCenter(5)
            R.id.scratch_prizes_game_type_bt_wubei -> {
            }
            R.id.scratch_prizes_game_type_bt_jingqing -> {
            }
        }
    }

    override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
        if (keyCode == KeyEvent.KEYCODE_BACK) { //监控/拦截/屏蔽返回键
            TowerGameExitWindows(this).showCenter()
            return false
        } else {
            return super.onKeyDown(keyCode, event)
        }
    }
}
